using System;
using FireStarterModeller.BO;
using FireStarterModeller.Test.BO;
using FireStarterModeller.UI;
using Habanero.Faces.Win;
using NUnit.Framework;

namespace FireStarterModeller.Test.UI
{
    [TestFixture]
    public class TestDMPropRuleControl
    {
        [TestFixtureSetUp]
        public void SetupFixture()
        {
            UITestUtils.SetupFixture();
        }


        [SetUp]
        public virtual void SetupTest()
        {
            UITestUtils.SetupTest();
        }

        [Test]
        public void Test_CreateControl_NullFactory_ShouldRaiseError()
        {
            //---------------Set up test pack-------------------
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            try
            {
                new DMPropRuleControl(null);
                Assert.Fail("expected ArgumentNullException");
            }
                //---------------Test Result -----------------------
            catch (ArgumentNullException ex)
            {
                StringAssert.Contains("Value cannot be null", ex.Message);
                StringAssert.Contains("controlFactory", ex.ParamName);
            }
        }

        [Test]
        public void TestSetBusinessObject_SetsProperty()
        {
            //---------------Set up test pack-------------------
            DMClass bo = TestUtilsShared.CreateSavedDMClassWithProps();
            DMProperty property = TestUtilsShared.CreateSavedDMProperty(bo);
            DMPropRuleControl control = new DMPropRuleControl(new ControlFactoryWin());
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            control.BusinessObject = property;
            //---------------Test Result -----------------------
            Assert.AreSame(property, control.Property);
            Assert.AreSame(property, control.BusinessObject);
//            Assert.AreEqual(property.PropRules.Count, control.PropRuleInfos.Count);
        }


        [Test]
        public void TestSetBusinessObject_SetsPropRuleParametersPropertyRule()
        {
            //---------------Set up test pack-------------------
            DMClass bo = TestUtilsShared.CreateSavedDMClassWithProps();
            DMProperty property = TestUtilsShared.CreateSavedDMProperty(bo);
            DMPropRuleControl control = new DMPropRuleControl(new ControlFactoryWin());
            //---------------Assert Precondition----------------
            Assert.IsNull(control.BusinessObject);
            Assert.IsNull(control.PropRuleParameterControl.BusinessObject);
            //---------------Execute Test ----------------------
            control.BusinessObject = property;
            //---------------Test Result -----------------------
            Assert.AreSame(property, control.Property);
            Assert.AreSame(property, control.BusinessObject);
            Assert.IsNotNull(control.PropRuleParameterControl.BusinessObject);
            //            Assert.AreEqual(property.PropRules.Count, control.PropRuleInfos.Count);
        }
        [Test]
        public void TestSetBusinessObjectDMProp()
        {
            //---------------Set up test pack-------------------
            DMClass bo = TestUtilsShared.CreateSavedDMClassWithProps();
            DMProperty property = TestUtilsShared.CreateSavedDMProperty(bo);
            DMPropRuleControl control = new DMPropRuleControl(new ControlFactoryWin());
            //---------------Assert Precondition----------------
            //---------------Execute Test ----------------------
            control.Property = property;
            //---------------Test Result -----------------------
            Assert.AreSame(property, control.Property);
            Assert.AreSame(property, control.BusinessObject);
//            Assert.AreEqual(property.PropRules.Count, control.PropRuleInfos.Count);
        }

        [Test]
        public void TestDisabledAtCreation()
        {
            //---------------Execute Test ----------------------
            DMPropRuleControl control = new DMPropRuleControl(new ControlFactoryWin());
            //---------------Test Result -----------------------
            Assert.IsFalse(control.Enabled);
        }

        [Test]
        public void TestSetEnables()
        {
            //---------------Set up test pack-------------------
            DMClass bo = TestUtilsShared.CreateSavedDMClassWithProps();
            DMProperty property = TestUtilsShared.CreateSavedDMProperty(bo);
            DMPropRuleControl control = new DMPropRuleControl(new ControlFactoryWin());
            //---------------Execute Test ----------------------
            control.BusinessObject = property;
            //---------------Test Result -----------------------
            Assert.IsTrue(control.Enabled);
        }

        [Test]
        public void TestSetToNullDisables()
        {
            //---------------Set up test pack-------------------
            DMClass bo = TestUtilsShared.CreateSavedDMClassWithProps();
            DMProperty property = TestUtilsShared.CreateSavedDMProperty(bo);
            DMPropRuleControl control = new DMPropRuleControl(new ControlFactoryWin());
            control.BusinessObject = property;
            //---------------Execute Test ----------------------
            control.Property = null;
            //---------------Test Result -----------------------
            Assert.IsFalse(control.Enabled);
        }


        //TestSetPropRuleInfo
        //TestLinkBetweenPropRuleAndParameters
    }
}